package com.power.sifa.approve.dao;


import com.power.sifa.approve.model.Aprv_materials_options_version;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 表单绑定生成材料文件版本记录 持久层(hibernate)
 */

public interface Aprv_materials_options_versionDao extends JpaRepository<Aprv_materials_options_version, Serializable>, JpaSpecificationExecutor<Aprv_materials_options_version>, Repository<Aprv_materials_options_version, Serializable>, Aprv_materials_options_versionDaoCustom<Aprv_materials_options_version, Serializable> {

    @Modifying
    @Transactional
    @Query("delete  from Aprv_materials_options_version s where  s.id in (:ids) ")
    void removeByIds(@Param("ids") List<Integer> ids);



    /**
     * 查询最大的版本
     * @param optionid
     * @return
     */
    @Query(value = "select max(s.version) from Aprv_materials_options_version s where  s.optionid = :optionid ", nativeQuery = true)
    Integer queryMaxVersion(@Param("optionid") String optionid);


    /**
     * 按照optionid删除数据
     * @param optionid
     * @return
     */
    @Modifying
    @Query(value = "delete from Aprv_materials_options_version s where s.optionid  = :optionid ", nativeQuery = true)
    void deleteByOptionId(@Param("optionid") String optionid);

}
